package com.own.business.resource.core.config;

import com.own.component.common.util.FileUtil;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

/**
 * ResourceWebMvcConfig
 *
 * @author chenxueli
 * @date 2023-07-07 13:58:37
 */
@Slf4j
@SpringBootConfiguration
public class ResourceWebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(@NonNull ResourceHandlerRegistry registry) {
        WebMvcConfigurer.super.addResourceHandlers(registry);
        var path = FileUtil.getStaticFileFolder().getAbsolutePath().concat(File.separator);
        log.info("静态资源目录：{}", path);
        registry.addResourceHandler("/files/**").addResourceLocations("file:" + path);
    }

}
